package com.caojing.haolemai.ui.outlets.outletsSharefragment;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.caojing.haolemai.R;

/**
 * Created by Administrator on 2016/10/19 0019.
 */
public class CustomPopupWindow extends PopupWindow {
    private View mMenuView;
    private TextView tv_Wxfriend, tv_Wx_cicler, tv_favor, tv_Cancel;


    public CustomPopupWindow(Activity context, View.OnClickListener itemsOnClick) {
        super(context);
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mMenuView = inflater.inflate(R.layout.alert_dialog_outletsfragment, null);
        tv_Wxfriend = (TextView) mMenuView.findViewById(R.id.textview_wx_friend);
        tv_Wx_cicler = (TextView) mMenuView.findViewById(R.id.textview_wx_circle);
        tv_favor = (TextView) mMenuView.findViewById(R.id.textview_wx_favor);
        tv_Cancel = (TextView) mMenuView.findViewById(R.id.textview_cancel);

        //取消
        tv_Cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //销毁弹出框
                dismiss();
            }
        });
        //设置按钮监听
        tv_Wxfriend.setOnClickListener(itemsOnClick);
        tv_Wx_cicler.setOnClickListener(itemsOnClick);
        tv_favor.setOnClickListener(itemsOnClick);

        //设置CustomPopupWindow的View
        this.setContentView(mMenuView);
        //设置CustomPopupWindow弹出窗体的宽
        this.setWidth(AbsListView.LayoutParams.MATCH_PARENT);
        //设置CustomPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);

        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        //设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.AnimBottom);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        //mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
        mMenuView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {

                int height = mMenuView.findViewById(R.id.pop_layout).getTop();
                int y=(int) motionEvent.getY();
                if(motionEvent.getAction()==MotionEvent.ACTION_UP){
                    if(y<height){
                        dismiss();
                    }
                }
                return true;
            }
        });

    }
}
